<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>系统管理</title>
<%@ include file="/common/util.jsp"%>
  <link href="${cdnctx}/dep/jquery/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

  var customerList = [];
  customerList = eval('${customerList}');
  var groupList = [];
  groupList = eval('${groupList}');
  function customerAutoComplete(){
    $("input[name='customername']").autocomplete({
      source:customerList,
      minLength:0
    });
    $("input[name='customername']").focus(function(){
    $(this).autocomplete('search');
    });

    $("input[name='groupname']").autocomplete({
      source:groupList,
      minLength:0
    });
    $("input[name='groupname']").focus(function(){
      $(this).autocomplete('search');
    });
  }

  $(function() {
    customerAutoComplete();
    if(${commonRole == login.roletype}){
      $("#companyrow").show();

    }
    if(${groupRole == login.roletype}){
      $("#grouprow").show();
    }


//    $("#groupcode").change(function(){
//      $("#customerInfoID").empty();
//      $.ajax({
//        async: false,
//        type: "POST",
//        contentType: "application/json",
//        url: "getCompanyListByGroup.shtml",
//        data: $("#groupcode").val(),
//        dataType: "json",
//        success: function(data) {
//          $("#customerInfoID").append("<option value=''>--请选择--</option>");
//          for (var i = 0; i < data.companyList.length; i++) {
//            $("#customerInfoID").append("<option value='" + data.companyList[i].id + "'>" + data.companyList[i].customername + "</option>");
//          }
//        },
//        error: function() {
//          dialog_alert("error");
//        }
//      });
//    });
     $("input[name='roletype']").click(function(){
       $("#customername").val('');
       $("#groupname").val('');
       var val = $("input[name='roletype']:checked").val();
       console.log(val);
       if(val==3){
         $("#companyrow").show();
         $("#grouprow").hide();
       }else{
         $("#companyrow").hide();
         $("#grouprow").show();
       }
     });
    $("#roleid").change(function(){
      var commonRole="${commonRole }";
      if(commonRole == $(this).find("option:selected").attr("roletype")){
        $("#loginTypeTr").show();
      }else{
        $("#loginTypeTr").hide();
      }
    });

    var loginId = "${login.id}";
    if(!loginId) {
      $("#addLoginForm").validate({
        rules: {
          'username': {
            required: true,
            existUserName: [$("#id").val()]
          },
          'password': {
            required: true
          },
          'cpassword': {
            required: true,
            equalTo: "#password"
          }
        },
        messages: {
          'username': {
            required: "用户名",
          },
          'password': {
            required: "密码",
          },
          'cpassword': {
            required: "确认密码"
          }
        },
        submitHandler:function(form){
          var selectName1 = $('input[name=customername]').val();
          var selectName2 = $('input[name=groupname]').val();

        if (customerList.indexOf(selectName1)>=0||groupList.indexOf(selectName2)>=0) {
          form.submit();
        }else{
           $("#error").text("请输入正确的单位名称");
        }
        }
      });
    }else{
      $("#addLoginForm").validate({
        rules: {
          'username': {
            required: true,
            existUserName: [$("#id").val()]
          },
          'cpassword': {
            equalTo: "#password"
          }
        },
        messages: {
          'username': {
            required: "用户名"
          }
        },
        submitHandler:function(form){
          var selectName1 = $('input[name=customername]').val();
          var selectName2 = $('input[name=groupname]').val();
          if (customerList.indexOf(selectName1)>=0||groupList.indexOf(selectName2)>=0) {
            form.submit();
          }else{
            $("#error").text("请输入正确的单位名称");
          }
        }
      });
    }
  });


</script>
</head>
<body class="main">
	<div class="-frame -style -luster" id="css_container">
		<!--首页框架页眉部分↓-->
		<%@ include file="/WEB-INF/pages/inc/header.jsp"%>
		<!--首页框架页眉部分↑-->

		<div class="content">

			<!-- Left导航菜单◎开始 -->
			<%@ include file="/WEB-INF/pages/inc/leftmenu.jsp"%>
			<!-- Left导航菜单◎结束 -->

			<div class="main-mid">
				<div class="pos"><img src="${cdnctx}/src/index/img/index.png"><a href="<%--${cdnctx}/system/systemMenu.shtml--%>">系统管理 ></a><a href="${cdnctx}/system/login/loginList.shtml">用户表管理 ></a><a><c:choose> <c:when test="${login.id == null}">新增</c:when><c:otherwise>编辑</c:otherwise></c:choose></a></div>
				<div class="css_contentDiv">
					<div class="searchDetailed  c-border-radius  b-box-shadow">
					<form id="addLoginForm" method="post" action="${cdnctx}/system/login/save.shtml">
                      <input type="hidden" id="roleid" name="roleid" value="${login.roleid}"/>
						  <input type="hidden"  name="pageIndex" value="${pageIndex}"/>
						  <input type="hidden"  id="id" name="id" value="${login.id}"/>
						  <table align="center" width="800" border="0" cellspacing="0" cellpadding="0">
             				  <tr>
             				 	 <td width="120" height="36" class="mainText"><label class="font14"><font color="red">*</font>用户名：</label></td>
             				 	 <td>
             				 	 <input type="text" class="form_input large" style="width:300px;" name="username" id="userName" value="${login.username}" maxlength="20" />（用户名必须字母开头，只能包含字母和数字。）
             				 	 </td>
             				 </tr>
             				  <tr id="passwordDiv">
             				 	 <td width="120" height="36" class="mainText"><label class="font14"><c:if test="${empty(login.id)}"><font color="red">*</font></c:if>密码：</label></td>
             				 	 <td>
             				 	 <input type="password" class="form_input large" style="width:300px;" name="password" id="password" maxlength="6" />
             				 	 </td>
             				 </tr>
             				 <tr id="cpasswordDiv">
             				 	 <td width="120" height="36" class="mainText"> <label class="font14"><c:if test="${empty(login.id)}"><font color="red">*</font></c:if>确认密码：</label></td>
             				 	 <td>
             				 	 <input type="password" class="form_input large" style="width:300px;"  id="cpassword" name="cpassword" maxlength="6" />
		                 	  </td>
             				 </tr>
                            <tr>
                              <td width="120" height="36" class="mainText"><label class="font14"><font color="red">*</font>用户类型：</label></td>
                              <td>
                                <input type="radio" id ="roletype" name="roletype" value="${commonRole}"
                                        <c:if test="${commonRole == login.roletype}">checked</c:if>/>普通用户 &nbsp;&nbsp;
                                <input type="radio" id ="roletype" name="roletype" value="${groupRole}"
                                       <c:if test="${groupRole == login.roletype}">checked</c:if>/>集团管理员
                              </td>
                            </tr>
                            <tr id="grouprow" style="display: none" >
                              <td width="120" height="36" class="mainText"><label class="font14"><font color="red">*</font>所属集团：</label></td>
                              <td>
                                <input class="form_input large" id = "groupname" name = "groupname" style="width:300px;" value="${login.groupname}"/>
                                <font id = "error" color = red></font>
                              </td>
                            </tr>
             				 <tr id="companyrow" style="display: none">
             				 	 <td width="120" height="36" class="mainText"><label class="font14"><font color="red">*</font>所属公司：</label></td>
             				 	 <td>
             				 	<input class="form_input large" id = "customername" name = "customername" style="width:300px;" value="${login.customername}"/>
                                  <font id = "error" color = red></font>
             				 	 </td>
             				 </tr>
             				  <tr>
             				 	 <td width="120" height="36" class="mainText"> <label class="font14">备注：</label></td>
             				 	 <td>
                       <textarea id="memo" name="memo" rows="4" cols="77" class="form_textarea large">${login.memo}</textarea>
             				 	 </td>
             				 </tr>
             				 <tr>
             				 	<td height="20"></td>
             				 </tr>
             				 
             				 <tr >
             				 	<td ></td>
						         <td>
						        <input type="submit" class="form_save" value="保&nbsp;存"/>
									  <input type="reset" class="form_cancle" value="取&nbsp;消"/>
				              	</td>
             				 </tr>
             				</table>
              		</form>
              		</div>
				</div>
			</div>

		</div>

		<!--首页框架页尾部分↓-->
		<%@ include file="/WEB-INF/pages/inc/footer.jsp"%>
		<!--首页框架页尾部分↑-->
	</div>
</body>
</html>